package com.zeroxml.cms.web.action.cms;

import com.zeroxml.cms.web.action.BaseAction;
import com.zeroxml.cms.service.ITagService;
import com.zeroxml.cms.service.IArticleService;
import com.zeroxml.cms.bo.Tag;
import com.zeroxml.cms.bo.Article;
import com.wyvoid.core.persistent.hibernate.HibernatePage;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.integration.spring.SpringBean;

import java.util.List;

/**
 * User: cjp
 * Date: 2007-9-22
 * Time: 8:02:47
 */
@UrlBinding("/tag.do")
public class TagAction extends BaseAction {
    @SpringBean
    private ITagService tagService;
    @SpringBean
    private IArticleService articleService;
    private List<Tag> tags;
    private HibernatePage<Article> articles;
    private long tagId;
    private int curPage;

    public void setTagService(ITagService tagService) {
        this.tagService = tagService;
    }

    public void setArticleService(IArticleService articleService) {
        this.articleService = articleService;
    }

    public List<Tag> getTags() {
        return tags;
    }

    public HibernatePage<Article> getArticles() {
        return articles;
    }

    public void setTagId(long tagId) {
        this.tagId = tagId;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    @DefaultHandler
    public Resolution viewTags(){
        tags=tagService.getTags();
        return getCmsResolution("tags");
    }

    public Resolution listArticles(){
        int pageSize=20;
        articles=articleService.getArticles(tagId,curPage,pageSize);
        return getCmsResolution("articlesByTag");
    }
}
